import {honor} from '../../../server/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
     gradelist:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
      this.getdata()
  },
async getdata(){
  const userid = wx.getStorageSync("id");
  const type = 1
  const data = await honor(userid,type)
  if(data.code == 200)
  {
    const res = data.result.map((item)=>{
      const datetime =  item.createTime.split(' ')[0]
      const time = this.formatDateString(datetime)
       item['datetime'] = time
      switch (item.honor) {
        case "1":
          item["icon"] = "../../../icon/等级图标/普通x280.png";
          item["dw"] = '普通'
          break;
        case "2":
          item["icon"] = "../../../icon/等级图标/青铜x280.png";
          item["dw"] = '青铜'
          break;
        case "3":
          item["icon"] = "../../../icon/等级图标/白银x280.png";
          item["dw"] = '白银'
          break;
        case "4":
          item["icon"] = "../../../icon/等级图标/黄金x280.png";
          item["dw"] = '黄金'
          break;
        case "5":
          item["icon"] = "../../../icon/等级图标/铂金x280.png";
          item["dw"] = '铂金'
          break;
        case "6":
          item["icon"] = "../../../icon/等级图标/钻石x280.png";
          item["dw"] = '钻石'
          break;
        default:
          break;
      }
      return item;
    })
    this.setData({ gradelist: res });
  }
},
formatDateString(dateStr) {
  const regex = /-/g; // 匹配所有的连字符
  const parts = dateStr.split(regex); // 将字符串按连字符分割成数组
  const year = parts[0];
  const month = parts[1];
  const day = parts[2];
  return `${year}年${month}月${day}日`; // 使用模板字符串拼接新格式
},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})